package com.huawei.M01.iterator.F25;

import java.util.ArrayList;
import java.util.List;

/**
 * 最小交换次数
 *
 * @author 111
 */
public class MinimumSwap {
    public int minimumSwap(String s1, String s2) {
        List<String> cache = new ArrayList<>();
        int count = 0;
        for (int i = 0; i < s1.length(); i++) {
            if (s1.charAt(i) != s2.charAt(i)) {
                if (cache.contains(String.valueOf(s1.charAt(i)))) {
                    count++;
                    cache.remove(String.valueOf(s1.charAt(i)));
                }else {
                    cache.add(String.valueOf(s1.charAt(i)));
                }
            }
        }

        if (cache.size() == 1) {
            return  -1;
        }else if (cache.size() == 2) {
            count += 2;
        }
        return count;
    }
    public static void main(String[] args) {
        System.out.println(new MinimumSwap().minimumSwap("xxxxyyyy", "yyyyxyyx"));
    }
}
